package itheima.com.MySemaphore;

import java.util.concurrent.Semaphore;

public class MyRunnable implements Runnable {
    //获取管理员对象
    private Semaphore semaphore = new Semaphore(2);

    @Override
    public void run() {
        try {
            //获取通行证
            semaphore.acquire();
            //开始行使
            System.out.println("获取了通行证开始行使");
            Thread.sleep(1000);
            System.out.println("归还通行证");
            //归还通行证
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
